#include"common_headers.h"
int searchfile31( char name[], char *outputfile )
{
	//DECLARATION
	int collect, is_mounted, is_valid_file_name;
	FILE *fptr=NULL;
	
	
	//INITIALIZATION
	collect = 0;
	is_mounted = 0;
	is_valid_file_name = 0;	
	
    l_nodeSearch *head;   
        
    //CHECK IF MOUNTED
    is_mounted = validateMountState();
    if(is_mounted)
    {
    	//CHECK IF VALID FILE NAME ('/' IS NOT ALLOWED IN FILE NAME)
    	is_valid_file_name = validateFileName(name);
		if(is_valid_file_name)
		{		
			//CHECK IF FILENAME SEARCHED IN HASH TABLE
			head=search_hashTable(ht_start,name);
			if(head!=NULL)
			{
				if((fptr=fopen(outputfile,"w"))!=NULL)
				{
					//WRITE ALL THE FILENAMES SEARCHED IN HASH TABLES
					while(head!=NULL)
					{
					    fprintf(fptr,"%s\n",head->data);
					    head=head->next;
					}
					fclose(fptr);
					collect=1;
					printf("searchfile_SUCCESS\n");				
				}
				else
				{
					//CANNOT OPEN FILE TO WRITE
					printf("searchfile_FAILURE: %s\n",ERR_VFS_SEARCHFILE_04); //To be added
				}
			}
			else
			{
				//FILE TO BE SEARCHED NOT FOUND			
				printf("searchfile_FAILURE: %s\n",ERR_VFS_SEARCHFILE_03);	//To be added			    
			}			
		}
		else
		{
			//INVALID CHARACTER IN FILENAME
			printf("searchfile_FAILURE: %s\n",ERR_VFS_SEARCHFILE_01);	//To be added
		}	
	}
    else
    {
    	//VFS NOT MOUNTED
    	printf("searchfile_FAILURE: %s\n",ERR_VFS_SEARCHFILE_02);
    }
	
	return collect;
}



